package main

func pivotIndex(nums []int) int {
	preSum := make([]int, len(nums))
	preSum[0] = 0
	for i, v := range nums {
		if i == len(nums) -1 {
			continue
		}
		preSum[i+1] = preSum[i] + v
	}
	postSum := make([]int, len(nums))
	postSum[len(nums)-1] = 0
	for i := len(nums) - 2; i >= 0; i-- {
		postSum[i] = postSum[i+1] + nums[i+1]
	}
	for i, pre := range preSum {
		post := postSum[i]
		if pre == post {
			return i
		}
	}
	return -1
}

func main() {
	println(pivotIndex([]int{2,1,-1}))
}